//
//  SISSCommonSignView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/1.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSCommonSignView.h"


@interface SISSCommonSignView ()

/* 甲方Label */
@property (weak, nonatomic) UILabel *firstPartyLabel;
/* 乙方Label */
@property (weak, nonatomic) UILabel *secondPartyLabel;
/* 居间人员Label */
@property (weak, nonatomic) UILabel *secondPartyAgentLabel;
/* 甲方签署日期Label */
@property (weak, nonatomic) UILabel *firstPartySignLabel;
/* 乙方方签署日期Label */
@property (weak, nonatomic) UILabel *secondPartySignLabel;
/// 牌号label
@property (weak, nonatomic) UILabel *licenseNoTitleLabel;


@end
@implementation SISSCommonSignView

- (void)setFirstPartyStr:(NSString *)firstPartyStr {
    _firstPartyStr = firstPartyStr;
    self.firstPartyLabel.text = firstPartyStr;
}

- (void)setSecondPartyStr:(NSString *)secondPartyStr {
    _secondPartyStr = secondPartyStr;
    self.secondPartyLabel.text = secondPartyStr;
}

- (void)setIsOneBottomSign:(BOOL)isOneBottomSign {
    _isOneBottomSign = isOneBottomSign;
    self.secondPartyAgentImageView.hidden = isOneBottomSign;
    [self.secondPartyImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake([SISSPublicSingleton shared].screenWidth - 32, ([SISSPublicSingleton shared].screenWidth - 64) * 0.4));
    }];
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    // 甲方
    UILabel *firstPartyLabel = [UILabel yyr_labelWithText:@"【甲方】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:firstPartyLabel];
    self.firstPartyLabel = firstPartyLabel;
    
    UILabel *firstPartyNamLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    firstPartyNamLabel.numberOfLines = 0;
    firstPartyNamLabel.font = [UIFont boldSystemFontOfSize:16];
    firstPartyNamLabel.text = @" ";
    [self addSubview:firstPartyNamLabel];
    self.firstPartyNamLabel = firstPartyNamLabel;
    
    // 甲方签名
    UIImageView *firstPartyImageView = [[UIImageView alloc] init];
    firstPartyImageView.backgroundColor = COLOR(0xD2E0EB);
    [self addSubview:firstPartyImageView];
    self.firstPartyImageView = firstPartyImageView;
    
    // 甲方签署日期
    UILabel *firstPartySignLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:firstPartySignLabel];
    self.firstPartySignLabel = firstPartySignLabel;
    
    // 乙方
    UILabel *secondPartyLabel = [UILabel yyr_labelWithText:@"【乙方】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:secondPartyLabel];
    self.secondPartyLabel = secondPartyLabel;
    
    UILabel *secondPartyNamLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    secondPartyNamLabel.numberOfLines = 0;
    secondPartyNamLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:secondPartyNamLabel];
    self.secondPartyNamLabel = secondPartyNamLabel;
    
    // 乙方居间人员
    UILabel *secondPartyAgentLabel = [UILabel yyr_labelWithText:@"【居间服务人员】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:secondPartyAgentLabel];
    self.secondPartyAgentLabel = secondPartyAgentLabel;
    
    UILabel *secondPartyAgentNameLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    secondPartyAgentNameLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:secondPartyAgentNameLabel];
    self.secondPartyAgentNameLabel = secondPartyAgentNameLabel;
    
    // 牌号
    UILabel *licenseNoTitleLabel = [UILabel yyr_labelWithText:@"【牌号】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:licenseNoTitleLabel];
    self.licenseNoTitleLabel = licenseNoTitleLabel;
    
    UILabel *licenseNoLabel = [UILabel yyr_labelWithText:@"  " fontSize:16 textColor:MAIN_TEXT_COLOR];
    licenseNoLabel.numberOfLines = 0;
    licenseNoLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:licenseNoLabel];
    self.licenseNoLabel = licenseNoLabel;
    
    // 乙方签名
    UIImageView *secondPartyImageView = [[UIImageView alloc] init];
    secondPartyImageView.backgroundColor = COLOR(0xD2E0EB);
    [self addSubview:secondPartyImageView];
    self.secondPartyImageView = secondPartyImageView;
    
    UIImageView *secondPartyAgentImageView = [[UIImageView alloc] init];
    secondPartyAgentImageView.backgroundColor = COLOR(0xD2E0EB);
    [self addSubview:secondPartyAgentImageView];
    self.secondPartyAgentImageView = secondPartyAgentImageView;
    
    UILabel *firstPartySignTimeLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    firstPartySignTimeLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:firstPartySignTimeLabel];
    self.firstPartySignTimeLabel = firstPartySignTimeLabel;
    // 乙方签署日期
    UILabel *secondPartySignLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:secondPartySignLabel];
    self.secondPartySignLabel = secondPartySignLabel;
    
    UILabel *secondPartySignTimeLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    secondPartySignTimeLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:secondPartySignTimeLabel];
    self.secondPartySignTimeLabel = secondPartySignTimeLabel;

}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    CGSize oneSignImageSize = CGSizeMake([SISSPublicSingleton shared].screenWidth - 32, ([SISSPublicSingleton shared].screenWidth - 64) * 0.4);
    CGSize twoSignImageSize = CGSizeMake(([SISSPublicSingleton shared].screenWidth - 32) * 0.5, ([SISSPublicSingleton shared].screenWidth - 32) * 0.5);
    // 甲方
    [self.firstPartyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).offset(margin);
        make.left.equalTo(weakSelf).offset(margin);
    }];
    [self.firstPartyNamLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartyLabel.mas_right);
        make.right.lessThanOrEqualTo(weakSelf).offset(-2 * margin).priority(999);
        make.top.equalTo(weakSelf.firstPartyLabel);
    }];
    
    // 甲方签名
    [self.firstPartyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartyLabel);
        make.top.equalTo(weakSelf.firstPartyLabel.mas_bottom).offset(margin);
        make.size.mas_equalTo(oneSignImageSize);
    }];
    // 甲方签署日期
    [self.firstPartySignLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartyImageView);
        make.top.equalTo(weakSelf.firstPartyImageView.mas_bottom).offset(margin);
    }];
    [self.firstPartySignTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartySignLabel.mas_right);
        make.centerY.equalTo(weakSelf.firstPartySignLabel);
    }];
    // 乙方
    [self.secondPartyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.firstPartySignLabel.mas_bottom).offset(4 * margin);
        make.left.equalTo(weakSelf.firstPartyLabel);
    }];
    [self.secondPartyNamLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartyLabel.mas_right);
        make.right.lessThanOrEqualTo(weakSelf).offset(-2 * margin).priority(999);
        make.top.equalTo(weakSelf.secondPartyLabel);
    }];
    [self.secondPartyAgentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartyLabel);
        make.top.equalTo(weakSelf.secondPartyNamLabel.mas_bottom).offset(margin);
    }];
    [self.secondPartyAgentNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.secondPartyAgentLabel);
        make.left.equalTo(weakSelf.secondPartyAgentLabel.mas_right);
    }];
    [self.licenseNoTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartyAgentLabel);
        make.top.mas_equalTo(weakSelf.secondPartyAgentLabel.mas_bottom).offset(margin);
    }];
    [self.licenseNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.licenseNoTitleLabel);
        make.left.equalTo(weakSelf.licenseNoTitleLabel.mas_right);
    }];
    
    // 乙方签名
    [self.secondPartyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.licenseNoTitleLabel.mas_bottom).offset(margin);
        make.left.equalTo(weakSelf.firstPartyImageView);
        make.size.mas_equalTo(twoSignImageSize);
    }];
    
    [self.secondPartyAgentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.secondPartyImageView);
        make.left.equalTo(weakSelf.secondPartyImageView.mas_right).offset(2 * margin);
        make.size.equalTo(weakSelf.secondPartyImageView);
    }];
    
    // 乙方签署日期
    [self.secondPartySignLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartyImageView);
        make.top.equalTo(weakSelf.secondPartyImageView.mas_bottom).offset(margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    [self.secondPartySignTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartySignLabel.mas_right);
        make.centerY.equalTo(weakSelf.secondPartySignLabel);
    }];

}

@end
